﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EarringsBackEnd
{
    public partial class frmGetDistanceFromPoint : Form
    {
        private Boolean clicked_once = false;
        private Point point1;
        private Point point2;

        public frmGetDistanceFromPoint()
        {
            InitializeComponent();
        }

        private void btnOpenFile_Click(object sender, EventArgs e)
        {
            openFD.Filter = "JPEG Compressed Image (*.jpg|*.jpg" + "|GIF Image(*.gif|*.gif" + "|Bitmap Image(*.bmp|*.bmp";
            openFD.Multiselect = true;
            openFD.FilterIndex = 1;
            if (openFD.ShowDialog() == DialogResult.OK)
            {
                Image image = Image.FromFile(openFD.FileName);
                if (image.Width < picBxCustomer.Width && image.Height < picBxCustomer.Height) 
                { 
                    picBxCustomer.SizeMode = PictureBoxSizeMode.Normal;                   
                } 
                else 
                { 
                    picBxCustomer.SizeMode = PictureBoxSizeMode.Zoom; 
                }

                picBxCustomer.Image = image;
                //picBxCustomer.Image = Image.FromFile(openFD.FileName);
            }
            else
            {
                MessageBox.Show("Operation Canceled");
            }
        }

        private void picBxCustomer_MouseClick(object sender, MouseEventArgs e)
        {
            if (clicked_once == false)
            {
                clicked_once = true;
                point1 = e.Location;
            }
            else if (clicked_once == true)
            {
                clicked_once = false;
                point2 = e.Location;
                int distance = Math.Abs(point1.X - point2.X);
                MessageBox.Show("Distance of pixels horizontally: " + distance.ToString());
            }
        }

        private void btnOverlap_Click(object sender, EventArgs e)
        {
            Bitmap baseImage;
            Bitmap baseImage2;
            Bitmap overlayImage;

            baseImage = (Bitmap)Image.FromFile(@"C:\Users\Administrator\Downloads\anne18.jpg");

            baseImage2 = (Bitmap)Image.FromFile(@"C:\Users\Administrator\Downloads\ER-002.png");

            //ImageManagement imgMgmt = new ImageManagement();
            //imgMgmt.AutosizeImage(baseImage2, 36, 36,0, @"C:\Users\Administrator\Downloads\ER-003.png");

            overlayImage = (Bitmap)Image.FromFile(@"C:\Users\Administrator\Downloads\ER-002.png");

            var finalImage = new Bitmap(overlayImage.Width, overlayImage.Height, PixelFormat.Format32bppArgb);
            var graphics = Graphics.FromImage(finalImage);
            graphics.CompositingMode = CompositingMode.SourceOver;

            graphics.DrawImage(baseImage, 0, 0);
            graphics.DrawImage(overlayImage, 0, 0);

            //show in a winform picturebox
            picBxCustomer.Image = finalImage;

            //save the final composite image to disk
            finalImage.Save(@"C:\Users\Administrator\Downloads\final.jpg", ImageFormat.Jpeg);
        }
    }
}
